package com.kaitian.demo.demo_boot_starter.service.impl;

import com.kaitian.demo.demo_boot_starter.annotation.LogAnnotation;
import com.kaitian.demo.demo_boot_starter.dto.DemoDO;
import com.kaitian.demo.demo_boot_starter.mapper.DemoMapper;
import com.kaitian.demo.demo_boot_starter.service.IDemoService;
import com.kaitian.demo.demo_boot_starter.utils.RedisUtil;
import com.kaitian.demo.demo_boot_starter.validator.DemoValidator;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CachePut;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.multipart.MultipartFile;

/**
 * @author ：xietian
 * @version ：V1.0
 * @program ：demo
 * @date ：Created in 2022/4/8 15:49
 * @description ：
 */
@Slf4j
@Service
public class DemoServiceImpl implements IDemoService {

    @Autowired
    private RabbitTemplate rabbitTemplate;

    @Autowired
    private RedisTemplate redisTemplate;

    @Autowired
    private RedisUtil redisUtil;

    @Autowired
    private DemoMapper demoMapper;

    @InitBinder
    public void initBinder(WebDataBinder binder) {
        // 绑定验证器
        binder.setValidator(new DemoValidator());
    }

    @LogAnnotation(module = "service", operator = "getById")
    @Override
//    @CachePut(value = "redisCache:demo:", key = "#id")
    public DemoDO getById(Integer id) {
        return demoMapper.getById(id);
    }

    @LogAnnotation
    @Override
//    @CachePut(value = "redisCache:demo:", key = "#id")
    public DemoDO getByParam(Integer id, String param) {
        return demoMapper.getById(id);
    }

    @LogAnnotation
    @Override
//    @CachePut(value = "redisCache:demo:", key = "#id")
    public DemoDO getByParamFiles(Integer id, MultipartFile[] files) {
        return demoMapper.getById(id);
    }

    @Async
//    @Scheduled(fixedRate = 10000000)
    @Override
    public void printStr() {
        log.info("LOG: 再接口中写方法实现");
        log.info("Scheduled: 定时器调度");
//        rabbitTemplate.convertAndSend("ebay.crm.exchange", "ebay.crm.cbt.report.key", "xxxxxxx");
        log.info("MQ: 异步消息发送");
    }
}